Ext.define('DragonApp.util.String', {

  statics : {

    //=========
    //必填渲染
    //=========
    required: '<span style="color:red;font-weight:bold" data-qtip="必填字段"> *</span>',


    //时间戳转时间,value为PHP传来的MySQL时间戳
    stampToDatetimeRenderer: function(value){

      if (value == null || value == 0 || value == '0' || value == '') {
        return '';
      } else {
        return Ext.util.Format.date(new Date(value * 1000),'Y-m-d H:i:s');
      }
    },

    //百分比渲染
    pctRenderer:  function(val) {

      var out = Ext.util.Format.number(val, '0.00%');
      if (val > 0) {
        return '<span style="color:' + "#73b51e" + ';">' + out + '</span>';
      } else if (val < 0) {
        return '<span style="color:' + "#cf4c35" + ';">' + out + '</span>';
      }
      return out;
    },

    //电子信箱链接
    emailRenderer: function(value) {
        return Ext.String.format('<a href="mailto:{0}">{1}</a>', value, value);
    },

    //图像链接(定制尺寸)
    imgRenderer: function(src, width, height) {
        return Ext.String.format('<img src="{0}"  width="{1}" height="{2}" alt="" />', src,width, height);
    },

    //文字悬浮提示
    contentRender: function(value, metadata, record, rowIndex, columnIndex, store) {

      if (typeof(value) == "undefined") {
        value = '';
        metadata.tdAttr = 'data-qtip="'+value+'" '+'data-qalign="bl-br"'+ 'data-qwidth="auto"';
        return value;
      }else{
        metadata.tdAttr = 'data-qtip="'+value+'" '+'data-qalign="bl-br"'+ 'data-qwidth="auto"';
        return value;
      }
    },

    //删除空格及Html标记
    delHtmlTag: function (str){
      var temp = str.replace(/<[^>]+>/g,"");
      var temp1 = temp.replace(/ /g,"");
      return temp1;
     },

    //删除字符串所有空格
    removeAllSpace: function(str) {
      return str.replace(/\s+/g, "");
    },

    //删除字符串最后一个字符
    removeLastChar: function(str) {
      return( str.substring(0,str.length-1) );
    },

    /*
     * 兼容IE的自定义函数
     */
    extendTrim: function() {

      String.prototype.trim=function(){
          return this.replace(/(^\s*)|(\s*$)/g, "");
      };

      String.prototype.ltrim=function(){
          return this.replace(/(^\s*)/g,"");
      };

      String.prototype.rtrim=function(){
          return this.replace(/(\s*$)/g,"");
      };
    },
    /**
     * [retRender description]
     * @type {[type]}
     */
    retentionRender: function(value, record){

      var register = record.get('register');

      if(value === null){
        return null;
      }else if(Ext.isEmpty(register)){
        return '0';
      }
      return Ext.util.Format.number((value/register)*100, '0.00%');
    }
  }
});